<template>
  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="附件序号" align="center" prop="id" />
      <el-table-column label="文件路径" align="center" prop="filePath">
        <template #default="scope">
          <div
            v-for="(item, index) in scope.row.filePath.split(',')"
            :key="'lesseeFile附件' + index"
          >
            <el-link
              :href="scope.row.filePath"
              :underline="false"
              download
              target="_blank"
              type="primary"
            >
              {{
                item
                  .split('/')
                  .pop()
                  .replace(/(.*)_\d+(\.[^.]+)$/, '$1$2')
              }}
            </el-link>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="文件名称" align="center" prop="fileName" />
      <el-table-column label="文件类别" align="center" prop="fileCategory" />
      <el-table-column label="存放物理位置" align="center" prop="fileLocation" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="状态" align="center" prop="status">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.SYS_STATUS" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        :formatter="dateFormatter"
        width="180px"
      />
    </el-table>
  </ContentWrap>
</template>
<script setup lang="ts">
import { DICT_TYPE } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import { LesseeApi } from '@/api/zszx/lessee'

const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗

const props = defineProps<{
  belongId?: number // 归属序号（主表的关联字段）
}>()
const loading = ref(false) // 列表的加载中
const list = ref([]) // 列表的数据

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    list.value = await LesseeApi.getLesseeFileListByBelongId(props.belongId)
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 初始化 **/
onMounted(() => {
  getList()
})
</script>
